<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>查询工作报告列表</title>
		<!-- css代码 start -->
		<link href="../../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../../css/global.css" rel="stylesheet" />
		<link href="../../../../css/style.css" rel="stylesheet" />
		<link href="../../../../css/task.css" rel="stylesheet" />
		<style>
			#div {
			    width: 0px;
			    height: 0px;
			    background: red;
			    position: fixed;
			    top: 70%;
			    left: 50%;
		   }

		   /*移除底部或顶部三角,需要在删除此代码*/
		   .mui-popover .mui-popover-arrow:after {
				width: 0px;
		   }

			.mui-checkbox input[type=checkbox], .mui-radio input[type=radio]{
				top: 8px;
				right: -10px;
			}
			.lpl{
				width: 102px !important;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>

		<div id="div"></div>
		<div id="popover" class="mui-popover shadow popover">
		 <p class="title" id="title">您确定要删除该报告吗？</p >
		 <div class="btn_box">
		  <span class="fl" onclick="closePopover()">取消</span>
		  <span class="fr red" onclick="fixedDel()">确定</span>
		 </div>
		</div>

		<!-- html代码 start -->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">查询工作报告列表</h1>
		</header>
		<div class="mui-content">
			<div class="page_cen shadow title_num" id="dianji">服务通知编号：<span id="serviceNo" style="color: #ea1e1a;"></span></div>
			<div class="item_box" id="itemBox">

			</div>
		</div>
		<!-- html代码 end -->

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			var nPlanId;
			var serviceNo;
			// relServiceNo 报告类型（1=服务报告，2=Error Report，3=Hot Account Reprot，4=验收报告，5=安装质量报告，6=电话解决报告）
			function jumpToReportView(id, serviceNo, planId, relServiceNo, noticeId, realReportId, submitStatus, instrumentId) {
				if (relServiceNo == 1) {
					jumpTofFieldservice(id, serviceNo, planId, relServiceNo, noticeId, submitStatus);
				} else if (relServiceNo == 2) {
					app.jumpTo("/view/service/report/errorhot/errorReportEdit.html",
						"view/service/report/errorhot/errorReportEdit.html", {
							serviceNo: serviceNo,
							planId: planId,
							noticeId: noticeId,
							errId: realReportId,
							submitStatus: submitStatus
						})
				} else if (relServiceNo == 3) {
					app.jumpTo("/view/service/report/errorhot/hotReportEdit.html",
						"view/service/report/errorhot/hotReportEdit.html", {
							serviceNo: serviceNo,
							planId: planId,
							noticeId: noticeId,
							hotId: realReportId,
							submitStatus: submitStatus
						})
				} else if (relServiceNo == 4) {
					app.jumpTo("/view/service/report/acceptance/edit.html",
						"view/service/report/acceptance/edit.html", {
							reportGuid: id,
							submitStatus: submitStatus
						})
				} else if (relServiceNo == 5) {
					app.jumpTo("/view/service/report/installationquality/add.html",
						"view/service/report/installationquality/add.html", {
							reportId: id,
							serviceNo: serviceNo,
							planId: planId,
							ServiceNoticeId: noticeId,
							iqrId: realReportId,
							submitStatus: submitStatus,
							instrumentNo: instrumentId
						})
				} else if (relServiceNo == 6) {
					app.jumpTo("/view/service/report/phone/edit.html",
						"view/service/report/phone/edit.html", {
							reportGuid: id,
							submitStatus: submitStatus,
							planState: planState
						})
				}
			}

			function jumpTofFieldservice(id, serviceNo, planId, relServiceNo, noticeId, submitStatus) {
				app.showWaiting()
				ajaxGet(BASE_URL + 'cc/notice/getServiceNoticeDetailsAndReportCount', {
					serviceNo: serviceNo,
					serviceNoticeId: noticeId,
					planId: planId,
					enginnerId: app.getUser().enginnerId
				}, function(data) {
					console.log(JSON.stringify(data))
					app.closeWaiting()
					if (data.code === 200) {
						var city = data.data.serviceNotice.city
						var prov = data.data.serviceNotice.province
						var mdsign = data.data.serviceInstrument.mdsign
						var diviBu = data.data.serviceInstrument.diviBu
						var divi = diviBu.split("-")[0]
						var bu = diviBu.split("-")[1]
						var isWarranty = data.data.serviceNotice.isWarranty
						var serviceType = data.data.serviceNotice.serviceType
						var problem = data.data.serviceNotice.troubleDescription
						var subServiceType = data.data.serviceNotice.subServiceType

						//先判断是否有服务报告
						app.jumpTo("/view/service/report/fieldservice/report.html",
							"view/service/report/fieldservice/report.html", {
								planState : planState,
								serviceNo: serviceNo,
								reportId: id,
								planId: planId,
								noticeId: noticeId,
								isWarranty: isWarranty,
								serviceType: serviceType,
								subServiceType: subServiceType,
								divi: divi,
								bu: bu,
								city: city,
								prov: prov,
								problem: problem,
								mdsign: mdsign,
								submitStatus: submitStatus
							})

					} else {
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					app.toast(errorMsg)
				});
			}

			var needDelReportId; // 需要删除的报告id
			var needDelserviceNo;
			var needRelServiceNo;
			var needDelServiceResult; // 需要删除的报告的状态
			function fixedDel() {
				var self = plus.webview.currentWebview();
				mui("#popover").popover('toggle', document.getElementById("div"));
				app.showWaiting('删除中...')
				ajaxGet(BASE_URL + 'cc/report/info/deleteReport', {
					id: needDelReportId,
					enginnerId: app.getUser().enginnerId,
					serviceNo: needDelserviceNo,
					type: needRelServiceNo
				}, function(data) {
					app.closeWaiting()
					if (data.code === 200) {
						initData();
						// 刷新TL首页
						var indexTl=plus.webview.getWebviewById('view/main/indexTL.html');
						if(indexTl){
						    indexTl.evalJS('getMyTeamCount()')
						}
						// 1、刷新FSE首页
						var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
						if(indexFSE){
							indexFSE.evalJS('getList("1")')
						}
						var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
						if(conductList){
							conductList.evalJS('getList()')
						}
						var completedList = plus.webview.getWebviewById('view/service/notice/completedList.html');
						if(completedList){
							completedList.evalJS('initData()')
						}
						var acceptedList = plus.webview.getWebviewById('view/service/notice/acceptedList.html');
						if(acceptedList){
							acceptedList.evalJS('getList()')
						}
						
						var self = plus.webview.currentWebview();
						if(self.planState && self.planState < '2'){
							var signClose = plus.webview.getWebviewById('view/service/notice/signClose.html');
							if (signClose) {
								signClose.close()
							}
						}
						if(self.planState && self.planState == '4'){
							if(needRelServiceNo == 6 && needDelServiceResult == '1'){ // 判断删除的是否是已完成的电话报告
								ajaxGet(BASE_URL + "cc/PlanDetails/checkPlanDetailsVisitList", { //判断是否上过门
								    enginnerId: app.getUser().enginnerId,
								    serviceNo: needDelserviceNo
								}, function (data) {
								    if (data.code == 200) {
								        if (data.data && data.data.length > 0) { 
											app.toast('删除成功');
								            mui.back();
								        } else {
											app.toast('删除成功');
											var signIn = plus.webview.create('/view/service/notice/signIn.html', 'view/service/notice/signIn.html', null,
											{
											    ServiceNoticeId: self.noticeId,
											    serviceNo: needDelserviceNo,
											    planId: self.planId
											})
											signIn.show();
								        }
								    } else {
								        app.toast(data.msg)
								    }
								}, function (errorMsg) {
								    app.toast(errorMsg)
								});
							} else if(self.phoneRep){
								app.toast('删除成功');
								mui.back();
							} else {
								app.toast('删除成功');
								var signIn = plus.webview.create('/view/service/notice/signIn.html', 'view/service/notice/signIn.html', null,
								{
								    ServiceNoticeId: self.noticeId,
								    serviceNo: needDelserviceNo,
								    planId: self.planId
								})
								signIn.show();
							}
							setTimeout(function () {
								var signClose = plus.webview.getWebviewById('view/service/notice/signClose.html');
								if (signClose) {
									signClose.close()
								}
								var workReportList = plus.webview.getWebviewById('view/service/report/work/workReportList.html');
								if (workReportList) {
									workReportList.close()
								}

							},500)
							return
						}
						app.toast('删除成功');
						mui.back();
					} else if (data.code === 203) {
						app.toast(data.msg)
					} else {
						app.toast(data.msg)
						if(data.msg.indexOf('报告不存在') >= 0){
							initData();
						}
					}
				}, function(errorMsg) {
					app.closeWaiting()
					app.toast(errorMsg)
				})
			}

			function closePopover() {
				mui("#popover").popover('toggle', document.getElementById("div"));
			}

			function delReport(reportId, serviceNo, relServiceNo, noticeId, planId, serviceResult) {
				needDelReportId = reportId;
				needDelserviceNo = serviceNo;
				nPlanId = planId;
				needRelServiceNo = relServiceNo;
				needDelServiceResult = serviceResult;
				mui("#popover").popover('toggle', document.getElementById("div"));
			}

			function initData() {
				app.showWaiting()
				ajaxGet(BASE_URL + "cc/report/info/getReportList", {
					"serviceNo": h('#serviceNo').html(),
					// "EnginnerId": app.getUser().enginnerId
				}, function(data) {
					app.closeWaiting()
					if (data.code === 200) {
						var str = '';
						if (data.data && data.data.length > 0) {
							console.log(JSON.stringify(data))
							for (var c = 0; c < data.data.length; c++) {
								var idTemp = data.data[c].id;
								var serviceNoTemp = data.data[c].serviceNo;
								var planIdTemp = data.data[c].planId;
								var relServiceNoTemp = data.data[c].relServiceNo;
								var noticeIdTemp = data.data[c].noticeId;
								var batchTypeTemp = data.data[c].batchType;
								var submitStatus = data.data[c].syncFlag;
								var fseName = data.data[c].fseName;
								if (JS.IsNullOrEmpty(fseName)) {
									fseName = ""
								}
								var customerName = data.data[c].customerName
								if (JS.IsNullOrEmpty(customerName)) {
									customerName = ""
								}
								var instrumentNo = data.data[c].instrumentNo
								if (JS.IsNullOrEmpty(instrumentNo)) {
									instrumentNo = ""
								}
								var instrumentId = data.data[c].instrumentId
								if (JS.IsNullOrEmpty(instrumentId)) {
									instrumentId = ""
								}
								var createTime = data.data[c].createTime;
								if (JS.IsNullOrEmpty(createTime)) {
									createTime = ""
								}

								str += '<div class="item">';
								str += '<div class="bar">';
								str += '<span class="del" onclick="delReport(' + idTemp + ',' + serviceNoTemp + ',' + relServiceNoTemp +','+noticeIdTemp+','+planIdTemp+','+data.data[c].serviceResult+')">删除</span>';
								str += '<span class="number" onclick="jumpToReportView(' + idTemp + ',' + serviceNoTemp + ',' + planIdTemp +
									',' + relServiceNoTemp + ',' + noticeIdTemp + ',' + batchTypeTemp + ', '+submitStatus+','+instrumentId+')">' + data.data[c].id +
									'<img src="../../../../images/icon_204.png" /></span>';
								str += '</div>';
								str += '<div class="type" onclick="jumpToReportView(' + idTemp + ',' + serviceNoTemp + ',' + planIdTemp +
									',' + relServiceNoTemp + ',' + noticeIdTemp + ',' + batchTypeTemp + ', '+submitStatus+','+instrumentId+')">';
								str += '<p><img src="../../../../images/icon_219.png"/><span class="lpl fl">FSE：</span><span>'+ fseName +'</span></p>';
								str += '<p><img src="../../../../images/icon_201.png"/><span class="lpl fl">客户名称：</span><span>'+ customerName +'</span></p>';
								str += '<div style="clear: both"></div>';
								relServiceNo = data.data[c].relServiceNo;
								//报告类型（1=服务报告，2=Error Report，3=Hot Account Reprot，4=验收报告，5=安装质量报告，6=电话解决报告）
								if (relServiceNo == '1') {
									relServiceName = "现场服务报告";
								} else if (relServiceNo == '2') {
									relServiceName = "Error Report";
								} else if (relServiceNo == '3') {
									relServiceName = "Hot Account Reprot";
								} else if (relServiceNo == '4') {
									relServiceName = "安装验收报告";
								} else if (relServiceNo == '5') {
									relServiceName = "安装质量报告";
								} else if (relServiceNo == '6') {
									relServiceName = "电话解决报告";
								}
								str += '<p><img src="../../../../images/icon_203.png"/><span class="lpl fl">报告类型：</span><span>'+ relServiceName +'</span></p>';
								// str += '<p><img src="../../../../images/icon_217.png"/><div class="lpl">仪器型号：</div><span>'+ instrumentNo +'</span></p>'
								var serviceResult = data.data[c].serviceResult;
								if (JS.IsNullOrEmpty(serviceResult)) {
									serviceResult = "暂无"
								} else if(serviceResult == '1') {
									serviceResult = "完成"
								} else if(serviceResult == '2'){
									serviceResult = '未完成'
								}
								str += '<p><img src="../../../../images/icon_222.png"/><span class="lpl fl">服务结果：</span><span>'+ serviceResult +'</span></p>';
								var submitStr = ''
								if (data.data[c].syncFlag == 1) {
									submitStr = '已提交'
								} else {
									submitStr = '未提交'
								}
								str += '<p><img src="../../../../images/icon_224.png"/><span class="lpl fl">是否提交：</span><span>' + submitStr + '</span></p>';
								str += '<p><img src="../../../../images/icon_202.png"/><span class="lpl fl">创建日期：</span><span>' + createTime + '</span></p>';
								str += '<p><img src="../../../../images/icon_104_cur.png"/><span class="lpl fl">CC报告编号：</span><span>' + data.data[c].reportNo + '</span></p>';
								str += '</div></div>';
							}
							h('#itemBox').html(str);
						} else {
							noData()
						}

					} else {
						noData()
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					noData()
					app.toast("数据获取失败，请检查网络连接");
				});
			}

			function noData() {
				html = '<div class="nodata">—— 暂无数据 ——</div>';
				h("#itemBox").html(html);
			}

			var planState;
			(function($, doc) {
				var relServiceNo;
				var relServiceName;
				$.init();

				$.plusReady(function() {

					var self = plus.webview.currentWebview();
					planState = self.planState;
					serviceNo = self.serviceNo
					h('#serviceNo').html(self.serviceNo);
					initData()
				});
			}(mui, document));

			h("#dianji").tap(function(){
				app.jumpTo("/view/workArea/service/serveDetails.html", "view/workArea/service/serveDetails.html", {
					"serviceNo": serviceNo,
					"enginnerId": app.getUser().enginnerId
				})
			})

		</script>
		<!-- js代码 end -->
	</body>
</html>
